package com.coffee.dict;

import com.coffee.dict.annotation.CoffeeDict;
import com.coffee.dict.annotation.CoffeeDictMap;
import lombok.Getter;
import lombok.Setter;

import java.util.List;
import java.util.Map;

/**
 * @author songkui
 * @since 2019/5/8
 */
@Getter
@Setter
public class DictDataDetail {
    private DictTargetType dictTargetType;

    //当前字段翻译使用的字典
    private Map<String, String> dictDetail;

    //原字段
    private String sourceField;

    //目标字段，翻译的字段name的字段名称
    private String targetField;

   //是否是多个字典值拼接的形式
    private Boolean multiple;

    //原字段是null时的缺省值
    private String nullValue;

    //找不到字典对应时的缺省值
    private String definedValue;

    //当翻译字段是实体类或者集合的时候，将每个字段的信息放到这个里面
    private List<DictDataDetail> listDictInfo;


    public DictDataDetail(String sourceField, Map<String, String> dictDetail, String targetField, boolean multiple, String nullValue, String definedValue) {
        this.dictTargetType= DictTargetType.FIELD;
        this.sourceField = sourceField;
        this.dictDetail = dictDetail;
        this.targetField = targetField;
        this.multiple = multiple;
        this.nullValue = nullValue;
        this.definedValue = definedValue;
    }

    public DictDataDetail(DictTargetType dictTargetType, String sourceField, List<DictDataDetail> listDictInfo) {
        this.dictTargetType = dictTargetType;
        this.sourceField = sourceField;
        this.listDictInfo = listDictInfo;
    }

    public DictDataDetail(CoffeeDictMap dictMap, Map<String, String> dictDetail) {
        this.dictTargetType = DictTargetType.FIELD;
        this.sourceField = dictMap.fieldName();
        this.dictDetail = dictDetail;
        this.targetField = dictMap.targetField();
        this.multiple = dictMap.multiple();
        this.nullValue = dictMap.nullValueName();
        this.definedValue = dictMap.definedValue();
    }

    // new DictDataDetail(field.getName(), coffeeDictCache.dictMapByName(coffeeDict.dictName()), coffeeDict.targetField(), coffeeDict.multiple(), coffeeDict.nullValueName(), coffeeDict.definedValue());
    public DictDataDetail(String sourceField, CoffeeDict coffeeDict, Map<String, String> dictDetail) {
        this.dictTargetType = DictTargetType.FIELD;
        this.sourceField = sourceField;
        this.dictDetail = dictDetail;
        this.targetField = coffeeDict.targetField();
        this.multiple = coffeeDict.multiple();
        this.nullValue = coffeeDict.nullValueName();
        this.definedValue = coffeeDict.definedValue();
    }


    @Override
    public String toString() {
        return "DictDataDetail{" +
                "dictTargetType=" + dictTargetType +
                ", sourceField='" + sourceField + '\'' +
                ", dictDetail=" + dictDetail +
                ", targetField='" + targetField + '\'' +
                ", multiple=" + multiple +
                ", nullValue='" + nullValue + '\'' +
                ", undefinedValue='" + definedValue + '\'' +
                ", collectionDictInfo=" + listDictInfo +
                '}';
    }
}
